package com.cesce.batch.cobros.service;

import java.io.File;
import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.cesce.batch.cobros.util.Constantes;

public class EnviarHostImpl implements EnviarHostService {

	@Autowired
	@Qualifier("ftpSendHost")
	private FtpService ftps;
	
	@Override
	public void send() throws Exception {

		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		
    	File srcFile= new File(Constantes.NAME_FTP_SEND);
    	File destFile= new File(Constantes.PATH_FTP_SEND + "COBROS_" +  sdf.format(new Date()) + ".txt");    	
    	FileUtils.copyFile(srcFile, destFile);
    	
    	ftps.setFileWithName(new FileInputStream(srcFile),Constantes.NAME_FTP_SEND);
	}

}
